package com.gitee.wsl.ext.string


fun String.indicesOf(
    phrase: String,
): Set<Int> {
    val indices = mutableSetOf<Int>()

    // No found
    val startIndexOf = indexOf(phrase, 0)
    if (startIndexOf < 0) {
        return emptySet()
    }

    indices.add(startIndexOf)

    // The found is the only one
    if (startIndexOf == (lastIndex - phrase.length)) {
        return indices
    }

    var startingIndex = indexOf(phrase, startIndexOf + phrase.length)

    while (startingIndex > 0) {
        indices.add(startingIndex)
        startingIndex = indexOf(phrase, startingIndex + phrase.length)
    }

    return indices
}